<?php

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#	FILE:			site_specific/ggw.php
#	FUNCTION:		Formatting the Magnetic Resonance Technology page output
#	AUTHOR:			Cameron Morrow
#	CREATED:		18/09/2005
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# C A N   E D I T ?
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Compact?
$PAGE_COMPACT = (@$_GET["compact"]) ? true : false;

# See if editing
$edit_page = (@$_GET["edit"] == "true" && !$PAGE_PREVIEW) ? true : false;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# S T A R T   H T M L
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-AU\" xml:lang=\"en-AU\">\n";
echo "<!-- Created by Cameron Morrow for Zone 4 -->\n";
echo "<head>\n";
echo "\t<title>" . $PROJECT_TITLE . " - " . $PAGE_NAME . "</title>\n";
echo "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
echo "\t<script language=\"javascript\" type=\"text/javascript\" src=\"../site_specific/assets/scripts/tct.js\"></script>\n";
echo "\t<script language=\"javascript\" type=\"text/javascript\" src=\"../assets/scripts/xml.js\"></script>\n";
echo "\t<script language=\"javascript\" type=\"text/javascript\" src=\"../assets/scripts/popup.js\"></script>\n";
echo "\t<script language=\"javascript\" type=\"text/javascript\" src=\"../assets/scripts/editor/ckeditor.js\"></script>\n";
echo "\t<style type=\"text/css\">\n";
echo "\t\t@import url(\"../site_specific/assets/styles/main.css\");\n";
echo "\t\t@import url(\"../assets/styles/xml.css\");\n";
echo "\t</style>\n";
echo "</head>\n";

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# B O D Y
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "<body onload=\"parseImagePopups();\" class=\"" . ($PAGE_COMPACT ? "compact" : ($IS_SHOWING_LOGIN ? "login" : "")) . "\">\n";

# Start container
echo "<div id=\"container\">";

	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# H E A D E R
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	echo "<div id=\"header\">";
	echo "<h1>" . $PROJECT_TITLE . " - " . $PAGE_NAME . "</h1>\n";
	echo "</div>";

	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# N A V I G A T I O N
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	echo "<div id=\"nav\">\n";
	echo "<ul class=\"nav\">\n";

	# Top level pages
	$top_level_pages = $PAGES -> getChildrenOfPage("");
	
	# If navigation items found
	if (count($top_level_pages) > 0) {

		$counter = 0;

		# For each
		foreach ($top_level_pages -> getPageIDs() as $nav_page_id) {

			# Get page details
			$nav_page = $top_level_pages -> getPage($nav_page_id);

			# Get list of groups authorized to view this page
			$nav_page_authorized = explode(",", $nav_page -> getData("p_access"));
			
			# Get List of groups of users
			$nav_group_authorized= explode(",", $USER -> getGroup());

			# Ensure it can be viewed at current authorization
			$nav_page_authorized = (findArrayInArray($nav_page_authorized, $nav_group_authorized) !== false);

			# Ensure it's in the navigation
			$nav_page_in_navigation = ($nav_page -> getData("p_innavigation") == "1");

			# Get class for <li> item
			$item_class = ($nav_page -> getID() == $PAGES -> getPageAtDepth($PAGE_ID, 0)) ? array("active") : array();

			# Is first?
			if ($counter == 0) $item_class[] = "first";

			if ($nav_page_authorized && $nav_page_in_navigation) {

				$menu_item=explode("-",$nav_page -> getData("p_name"));
				# Open nav item
				echo "<li class=\"" . implode(" ", $item_class) . "\"><a href=\"../" . $nav_page -> getData("p_section") . "/" . $nav_page -> getID() . ".php\">" . $menu_item[0]. "</a></li>";

				$counter++;
			}
		}
	}

	# Close navigation
	echo "</ul>\n";
	echo "</div>";
	
	
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# M A I N   C O N T E N T
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			
	echo "<div id=\"maincontent\">\n";
	
	echo "<div id=\"maincontentleft\">\n";//contentHeader($PAGE_NAME,$PAGE_ID) .startContentBox();
	
	if($IS_AUTHORIZED){
		
		echo generateDropdownlistGroups();
	
		//echo "<ul id=\"verticalmenu\">";
//		
//			if($PAGE_ID == "xmlsiteeditor"){
//				
//				//if($USER -> getCanApprove()){
//			
//					echo "<li>";
//					
//						//echo $USER -> IsUserAuthorisedForLanguage();
//						
//						$arrLanguages =  getExistLans();
//						
//						echo "<select id=\"selLan\" onchange=\"onchange_triggerLanguageFilter()\" style=\"width:150px;\">";
//						
//							foreach($arrLanguages as $valueLanguages){
//
//								if($USER -> IsUserAuthorisedForLanguage($valueLanguages['x_language'])){
//									echo "<option value='".$valueLanguages['x_language']."'>".$valueLanguages['lan_name']."</option>";
//								}
//							}
//						
//						echo "</select>";
//						
//					echo "</li>";
//					
//					echo "<li>";
//					
//						$arrModules = getXMLModules();
//					
//						echo "<select id=\"selModules\" onchange=\"onchange_chooseModule()\" style=\"width:150px;\">";
//						
//						foreach($arrModules as $valueModules){
//							
//							if($valueModules['x_module'] == ""){
//								
//								echo "<option value='no module' onclick=\"onchange_chooseModule()\">no module</option>";
//							}
//							else{
//								
//								echo "<option value='".$valueModules['x_module']."' onclick=\"onchange_chooseModule()\">".$valueModules['x_module']."</option>";	
//							}
//						}
//						
//						echo "</select>";
//						
//					echo "</li>";
//					
//					echo "<li>";
//					
//						$arrSections = array();
//					
//						if(count($arrModules)> 0){
//					
//							$arrSections = getXMLSectionsInModule('en',$arrModules[0]['x_module']);
//						}
//					
//						echo "<select id=\"selSection\" onchange=\"onchange_triggerLanguageFilter()\" style=\"width:150px;\">";
//						
//						foreach($arrSections as $valueSections){
//						
//							echo "<option value='".$valueSections['x_section']."'>".$valueSections['x_section']."</option>";
//						}
//						
//						echo "</select>";
//						
//					echo "</li>";
//					
//					echo "<li>";
//					
//						echo "<select id=\"selStatus\" onchange=\"onchange_triggerLanguageFilter()\" style=\"width:150px;\">";
//						
//						echo "<option value=\"\" onclick=\"onchange_triggerLanguageFilter()\">All</option>";
//						
//						echo "<option value=\"1\" onclick=\"onchange_triggerLanguageFilter()\">Pending</option>";
//						
//						echo "<option value=\"2\" onclick=\"onchange_triggerLanguageFilter()\">Locked</option>";
//						
//						if($USER -> IsNameInGroup("Administrators") || $USER -> IsNameInGroup("Developers")){
//							
//							echo "<option value=\"3\" onclick=\"onchange_triggerLanguageFilter()\">Unapproved</option>";
//						
//							echo "<option value=\"4\" onclick=\"onchange_triggerLanguageFilter()\">Approved</option>";
//						}
//						
//						echo "</select>";
//						
//					echo "</li>";
//					
//				//}
//			}
//			
//		echo "</ul>";
	}
	echo "</div>";
	echo "</div>";
	  # RIGHT
	echo "<div id=\"maincontentright\" style=\"font-family:Arial;\">" ."<div class=\"cw\">";

		# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		# P A G E   C O N T E N T
		# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

		# Primary Output
		if ($edit_page && $USER -> getCanApprove()) {

			# Width?
			if ($PAGE_COMPACT) {
				$width = 670;
				$height = 400;
			} else {
				$width = 520;
				$height = 600;
			}

			# Flash editor
			$main_output = "<p>" . generatePageEditFlash("../assets/flash/editor3_02.swf?host=../&passed_width=" . $width . "&passed_height=" . $height . "&page=" . $PAGE_ID . "&type=page", $width, $height) . "</p>";
		} else {

			if (!isset($main_output)) {
				# Prep content
				$main_output = parseFlashLinks(parseFlashXML($PAGE_CONTENT));
				
			}
		}

		# ASK IF EDITING
		if ($USER -> getCanApprove() && !$PAGE_COMPACT && !$PAGE_PREVIEW) {
			echo "<div class=\"canedit\">";
			if (!$edit_page && $PAGE -> getData("p_custom_content") == "") {
				echo "<form name=\"edithispageform\" id=\"editthispageform\" action=\"" . $PAGE_ID . ".php\" method=\"get\">";
				echo "<p>As an administrator you can <input type=\"hidden\" name=\"edit\" id=\"edit\" value=\"true\" />";
				echo "<input type=\"submit\" value=\"Edit this page\" /></p>";
				echo "</form>";
				
			} else if ($PAGE -> getData("p_custom_content") == ""){
				echo "<form name=\"edithispageform\" id=\"editthispageform\" action=\"" . $PAGE_ID . ".php\" method=\"get\">";
				echo "<p>Once you have finished making changes, click <input type=\"hidden\" name=\"edit\" id=\"edit\" value=\"\" />";
				echo "<input type=\"submit\" value=\"Finished editing\" /></p>";
				echo "</form>";
			}

			if ($PAGE -> getData("p_custom_content") != "") {
				//echo "<p>Note: This page uses a custom content (<em>" . $PAGE -> getData("p_custom_content") . "</em>), so changes you make may not be reflected in the site proper.</p>";
			}
			echo "</div>";
		}

		# MESSAGES
		$messages_output = "";
		if (count($MESSAGE_ARRAY) > 0) {

			$messages_output .= "<ul id=\"messages\" class=\"messages\">\n";

			foreach ($MESSAGE_ARRAY as $message) {
				$messages_output .= "<li class=\"messagetype" . $message[1] . "\">" . $message[0] . "</li>";
			}

			$messages_output .= "</ul>\n";
		}
		echo $messages_output;
		
		# Fix main output
		$main_output = str_replace(
			array("%0a", "%09"),
			array("", ""),
			$main_output
		);

		# MAIN
		echo $main_output;


		# ERRORS
		if (count($ERROR_ARRAY) > 0 && $SHOW_ERROR_FEEDBACK) {

			echo "<h2>Errors (" . count($ERROR_ARRAY) . ")</h2>\n";
			echo "<ul id=\"errors\" class=\"messages\">";

			foreach ($ERROR_ARRAY as $error) {
				echo "<li class=\"messagetype" . $error[1] . "\">" . $error[0] . "</li>";
			}

			echo "</ul>\n";
		}

		# SQL QUERIES
		if (count($SQL_ARRAY) > 0 && $SHOW_SQL_FEEDBACK) {

			echo "<h2>SQL Queries (" . count($SQL_ARRAY) . ")</h2>\n";
			echo "<ul id=\"sqlqueries\" class=\"messages\">";

			foreach ($SQL_ARRAY as $sql_query) {
				echo "<li>" . $sql_query . "</li>";
			}

			echo "</ul>\n";
		}

	echo "</div>" .
		endContentBox();

  echo "</div>";
# End main content
echo "</div>";
		
  
  # For glossary page


  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # F O O T E R
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  echo "<div id=\"footer\">\n";
  echo "<p>Copyright &copy; Zone4, 2010 | \n";
  if ($USER -> isLoggedIn()) {
	  echo "<a href=\"../admin/adminhome.php\">admin</a> | <a href=\"?logout=1\">logout</a> | Logged in as <strong>" . $USER -> getFirstName() . " " . $USER -> getLastName() . "</strong> (" . $USER -> getGroupName() . ")";
  } else {
	  echo "<a href=\"../admin/adminhome.php\">admin</a>";
  }
  echo " | v" . $EDITOR_VERSION . "</p>\n";
  echo "<p><a href=\"http://validator.w3.org/check?uri=referer\">XHTML</a> | CSS</p>";
  echo "</div>\n";

# End container
echo "</div>";


echo "<div id=\"popup\" >";//style=\"display: none;background:#EFEFEF;color:#222222;border:solid;border-color:#C0C0C0;width:600px;height:400px;\"
echo "<div id=\"handle\" style=\"\">";
 echo "<form name=\"popupform\" id=\"popupform\" action=\"" . $PAGE_ID . ".php\" method=\"get\">";
 
 echo "</form>";
 echo "</div>";
echo "</div>";

echo "<div id=\"modal\" style=\"display:none;\">";

echo "</div>";

/*echo "<script language=\"javascript\">";
echo "var theHandle = document.getElementById(\"handle\");";
echo "var theRoot   = document.getElementById(\"popup\");";
echo "Drag.init(theHandle, theRoot);";
echo "</script>";*/


# End
echo "</body>" .
	"</html>";
?>